package com.engine.modules.system.controller;

import com.engine.common.baseEntity.jsonResponse.JsonResponseEntity;
import com.engine.common.constant.CommonConstant;
import com.engine.common.exception.InvalidTokenRuntimeException;
import com.engine.common.util.ListMapAndJson;
import com.engine.init.InitDataList;
import com.engine.init.entity.TablePropertieEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@RestController
@CrossOrigin
@Api(tags = "9-后台接口")
@RequestMapping("/System/Config")
@ApiSort(value = 99)
@Slf4j
public class ConfigController {

    @ApiOperation(value="刷新引擎后台",notes= "刷新引擎后台，会重新读取全部表配置文件")
    @GetMapping(value = "/refresh")
    public String refresh(HttpServletResponse response) {
        try {
            String string = InitDataList.initAndRefresh();
            JsonResponseEntity jsonResponseEntity = new JsonResponseEntity(true, CommonConstant.SC_OK_200,"初始化成功",string,0,response);
            return jsonResponseEntity.getJsonString();
        }
        catch (Exception e) {
            log.error(e.getMessage(), e);
            JsonResponseEntity jsonResponseEntity = new JsonResponseEntity(false, CommonConstant.SC_BK_ERROR, "查询出错，e：" + e.getMessage(), response);
            return jsonResponseEntity.getJsonString();
        }
    }



    @ApiOperation(value="test")
    @GetMapping(value = "/test")
    public String test(HttpServletResponse response) throws IOException {
        JsonResponseEntity jsonResponseEntity = new JsonResponseEntity(true,200,"成功",1,1,response);
        return jsonResponseEntity.getJsonString();
    }




}
